package com.wise.service.cms.content.advice;

import com.wise.summer.v1.cms.content.advice.DeleteAdvice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Service;
import org.summerframework.model.SummerService;
import org.summerframework.model.SummerServiceBean;

import java.util.List;

/**
 * 批量删除推荐搜索关键字-链接
 *
 * @author Haoming Chen
 * Created on 2019/11/14
 */
@Service
@SummerService
public class DeleteAdviceService implements SummerServiceBean<DeleteAdvice> {

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Autowired
    NamedParameterJdbcTemplate npJdbcTemplate;

    @Autowired
    public DeleteAdviceService(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate npJdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
        this.npJdbcTemplate = npJdbcTemplate;
    }

    @Override
    public void sum(DeleteAdvice model) {
        List<String> idList = model.getId();
        MapSqlParameterSource mapSqlParameterSource = new MapSqlParameterSource();
        int result = 0;
        if (idList.size() > 0) {
            mapSqlParameterSource.addValue("urlIdList", idList);
            result = npJdbcTemplate.update("update market_search_advice set is_delete = 1 where id in (:urlIdList)",
                    mapSqlParameterSource);
        }
        model.setSummerResult(result == 0 ? false : true);
    }
}
